/* global appConfig */
/* global App */
require(["common", "coAjax", "queryString", "hash_routie"], function (jSouper, coAjax, QueryString, hash_routie) {
	//放置监听HASH变动
	function _init_hash() {
		hash_routie.on("tags", function () {
			var queryString = new QueryString(location.hash);
			var tag_id = queryString.get("tag_id");
			var tags_detail = App.get("$Cache.tags_detail");
			for (var i = 0, tag; tag = tags_detail[i]; i += 1) {
				if (tag._id == tag_id) {
					App.set("$Cache.pointer_tag", tag);
					break;
				}
			}
			if (i == tags_detail.length) {
				App.set("$Cache.pointer_tag", tags_detail[0]);
			}
		});
	}
	

	// 加载标签列表
	coAjax.get(appConfig.bus.tags_detail, {
		bus_id: appConfig.bus_id
	}, function (result) {
			App.set("$Cache.tags_detail", result.result);
			_init_hash();
		});
});